package config

import (
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

var DB *gorm.DB

func InitDB() {
	dsn := "root:@@wuliaoge111@tcp(8.134.195.118:3306)/restaurant_db?charset=utf8mb4&parseTime=True&loc=Local"
	initDBWithDSN(dsn)
}

func InitTestDB() {
	dsn := "root:@@wuliaoge111@tcp(8.134.195.118:3306)/restaurant_test_db?charset=utf8mb4&parseTime=True&loc=Local"
	initDBWithDSN(dsn)
}

func initDBWithDSN(dsn string) {
	var err error
	DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic("Failed to connect to database: " + err.Error())
	}
}
